package it.apiconsulting.live.view;

import it.apiconsulting.live.controller.UtenteManager;
import it.apiconsulting.live.model.Utente;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {
	
	private static final long serialVersionUID = 9149826260758390091L;
	private String username;
	private String password;
	private List<Utente> utenti;
	private Long id;

	private UtenteManager linkController;
	
	public LoginAction() {
		linkController = new UtenteManager();
	}

	public String execute() {
		boolean find = false;
		this.utenti = linkController.list();
		
		for (int i = 0; i < utenti.size(); i++) {
			if (utenti.get(i).getUsername().equals(username) && 
					utenti.get(i).getPassword().equals(password))
				find = true;
			if (find) break;
		}
		
		if (find) return SUCCESS;
		else return ERROR;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
}